package com.ch4;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * @author woldier
 * @version 1.0
 * @description synchronized
 * @date 2023/4/18 20:19
 **/
@Slf4j(topic = "t.ch4")
public class Demo01 {
    static int count =  5000;
    static final Object room = new Object();
    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                synchronized (room){
                    count--;
                }
            }
        },"减法器");

        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                synchronized (room){
                    count++;
                }
            }
        },"减法器");



        t1.start();
        t2.start();

        t1.join();
        t2.join();
        System.out.println(count);

    }


}
